<?php
require_once '../class/control.class.php';

include 'ckeditor/ckeditor.php';
$CKEditor = new CKEditor();
$CKEditor->returnOutput = true;
$CKEditor->basePath = 'ckeditor/';
$CKEditor->config['width'] = 750;
$CKEditor->config['language'] = "pt-br";
$CKEditor->config['toolbar'] = array(
	 array( 'Source', '-', 'Bold', 'Italic', 'Underline', 'Strike' ),
	 array( 'Image', 'Link', 'Unlink', 'Anchor' ));
$CKEditor->textareaAttributes = array("cols" => 80, "rows" => 10);

if($_GET['editar']){
	$obj = new Control('consultar','institucional',$_GET['editar']);
	$obj->Consult();
	$con = $obj->result->lista;
}
?>
<div id="load"><img src="images/wait.gif" /></div>
<div>
	<div id="box1">
		<div class="tituloBox" >Atualizar</div>
			<form id="formInst" method="post" enctype="multipart/form-data" >
				<table width="80%" border="0" cellspacing="5" cellpadding="0" align="center">
					<tr>
						<td>Conte&uacute;do:</td>
						<td>
						<?php 
							$lst = new Control('dropdown','institucional','');
							echo '<select name="idinstitucional" id="idinstitucional" class="input" onchange="editar(this.value,\'institucional\');" >';														
								$lst->Dropdown();
							echo '</select>';
						?>				
						</td>
						<td>&nbsp;</td>
					</tr>
					<?php if($_GET['editar']){ ?>
					<tr>
						<td>T&iacute;tulo:</td>
						<td><input name="titulo" id="titulo" type="text" class="input" value="<?php echo $_GET['editar'] ? $con['titulo'] : ''; ?>" /></td>
						<td></td>
					</tr>					
					<tr>
						<td>Imagem:</td>
						<td>
							<input name="imagem0" id="imagem0" type="file" class="input" />
							<br />
							<?php 
								if($con['imagem0'] != '')
									echo '<img src="../images/institucional/',$con['imagem0'],'" width="150" />';
							?>
						</td>
						<td></td>
					</tr>
					<tr>
						<td colspan="3">Texto:</td>
					</tr>
					<tr>	
						<td colspan="3">	
							<?php echo $CKEditor->editor("valor", $con['valor']); ?>	
						</td>
					</tr>						
					<tr align="right">
						<td colspan="3">
							<input type="hidden" name="acao" id="acao" value="update" />
							<input type="hidden" name="pagina" id="pagina" value="Institucional" />
							<input type="hidden" name="idinstitucional" id="idinstitucional" value="<?php echo $_GET['editar']; ?>" />
							<input type="submit" value="Salvar" />
						</td>
					</tr>
					<?php 
						}
					?>					
				</table>
			</form>
	</div>
	<script type="text/javascript"> 
        $(document).ready(function() { 
        	var options = { 
        			beforeSubmit:  loading,
        		    success:    sucesso,
        		    url:    '../class/server.php'
        		};
            $('#formInst').ajaxForm(options); 
            <?php if($_GET['editar']){ ?>
        		var idedit = <?php echo $_GET['editar']; ?>;
        		$('select#idinstitucional option[value="'+idedit+'"]').attr('selected','selected');
       		<?php } ?>
        }); 
    </script> 
</div>